<?php 
	defined('PHPFOX') or exit('NO DICE!'); 
?>
{if count($aSettings)}
{literal}
<script type="text/javascript">
   $Behavior.setDateTimePicker = (function(){
      $('#roommates_master_birthday').datepicker({
          dateFormat: "dd.mm.yy"
      });	  
      $('#roommates_master_birthday').click(function(){$('#roommates_master_birthday').focus();});
   });
		   
	$Behavior.tabSwitch = function(){
		if('{/literal}{$sTab}{literal}' == 'master')
		{
			$('#group_{/literal}{$iGroupMasterId}{literal}').click();
		}
	}
</script>
{/literal}
{if count($aGroups)}
<div class="page_section_menu">
	<ul>
		<li class="active">
			<a href="#" class="js_custom_change_group" id="group_basic">{phrase var='user.basic_information'}</a>
		</li>
	{foreach from=$aGroups name=groups item=aGroup}	
		<li class="{if $phpfox.iteration.groups == count($aGroups) && Phpfox::isModule('music') && !Phpfox::getUserParam('music.can_upload_music_public')} last{/if}"><a href="#" class="js_custom_change_group" id="group_{$aGroup.group_id}">{phrase var=$aGroup.phrase_var_name}</a></li>
	{/foreach}
	</ul>
	<div class="clear"></div>
</div>
{else}
<div class="main_break"></div>
{/if}

<div id="js_custom_public_message" class="public_message" style="margin-bottom:10px;">
	<a href="{url link='profile'}">{phrase var='user.view_your_updated_profile'}</a>
</div>

{literal}
 <script type="text/javascript">
	function saveAvatar(ele)
	{
		$('#js_photo_preview_ajax').html($.ajaxProcess('Saving'));
		$(ele).ajaxCall('pet.cropPhoto', 'js_disable_ajax_restart=true');
		return false; 	
	}
	
 </script>
{/literal}

{if Phpfox::isModule('pet')}
<div class="table js_custom_groups js_custom_group_basic">
	<div id="js_crop_tool">	
	{if (!empty($sProfileImage) && Phpfox::getUserBy('user_image'))}
		<h3>{phrase var='pet.your_current_avatar'}</h3>
		<div style="float:left; margin-right:10px;">
			<strong>{phrase var='user.thumbnail'}:</strong>
			<div class="p_2">
				{$sImageThumb}
			</div>
		</div>	
		<div style="float:left;">
			<strong>{phrase var='user.avatar'}:</strong>
			<div class="p_2" id="js_user_avatar">
				{$sImageAvatar}
			</div>
		</div>
		<div class="clear"></div>		
		{if $iImageWidth > 75 && $iImageHeight > 75}
			<h3>{phrase var='user.profile_picture_cropping_tool'}</h3>
			<div class="extra_info">
				{phrase var='user.click_and_drag_a_box_on_the_original_image_to_create_your_cropped_image'}
			</div>
			<div class="p_4">
				<div style="float:left; margin-right:10px;"> <strong>{phrase var='user.original'}:</strong>
					<div class="p_2" style="position:relative;">
						{$sProfileImage}
					</div>
				</div>
				<div id="js_photo_preview" style="display:none;">
					<strong>{phrase var='user.preview'}:</strong>
					<div class="p_2">
						<div style="position:relative; overflow:hidden; width:75px; height:75px; border:1px #000 solid;">
							{$sProfileImage2}
						</div>		
					</div>
				</div>
				<br style="clear:both;"/>
				<form method="post" action="#" onsubmit="return saveAvatar(this);">
					<div><input type="hidden" name="val[x1]" value="" id="x1" /></div>
					<div><input type="hidden" name="val[y1]" value="" id="y1" /></div>
					<div><input type="hidden" name="val[x2]" value="" id="x2" /></div>
					<div><input type="hidden" name="val[y2]" value="" id="y2" /></div>
					<div><input type="hidden" name="val[w]" value="" id="w" /></div>
					<div><input type="hidden" name="val[h]" value="" id="h" /></div>
					<div><input type="hidden" name="val[image_width]" value="{$iImageWidth}" /></div>
					<div><input type="hidden" name="val[image_height]" value="{$iImageHeight}" /></div>				
					<div style="margin-top:10px;">
						<input type="submit" value="{phrase var='user.save_avatar'}" id="js_save_profile_photo" class="button" /> <span id="js_photo_preview_ajax"></span>
					</div>
				</form>			
			</div>				
		{/if}
	{/if}
	</div>
	<form enctype="multipart/form-data" method="post" action="{url link='user.profile'}">
		<div id="js_upload_photo_form">		
			<div id="js_photo_form_holder">				
			<div class="table">						
				<div class="table_left">
					<label for="image">{phrase var='user.select_an_image'}:</label>
				</div>
				<div class="table_right">				
					<div id="js_progress_uploader"></div>
					<div class="extra_info">
						{phrase var='user.you_can_upload_a_jpg_gif_or_png_file'}
						{if $iMaxFileSize !== null}
						<br />
						{phrase var='user.the_file_size_limit_is_file_size_if_your_upload_does_not_work_try_uploading_a_smaller_picture' file_size=$iMaxFileSize|filesize}
						{/if}
					</div>				
				</div>
				<div class="clear"></div>					
			</div>
			<div class="table_clear">
				<input type="submit" value="{phrase var='user.upload_picture'}" class="button" name="val[uploaded]" />
			</div>	
		</div>
		</div>
	</form>
</div>
<div class="table js_custom_groups js_custom_group_{$iGroupMasterId}" style="display: none">	
	{if (!empty($sImageAvatar2) && $sMasterImage)}
		<h3>{phrase var='pet.current_avatar'}</h3>		
		<div style="float:left;">				
			<div class="p_2" id="js_user_avatar">
				{$sImageAvatar2}
			</div>
		</div>
		<div class="clear"></div>		
	<div class="separate"></div>
	{/if}		
	<form enctype="multipart/form-data" method="post" action="{url link='user.profile'}">
		<div id="js_upload_photo_form2">		
			<div id="js_photo_form_holder2">				
			<div class="table">						
				<div class="table_left">
					<label for="image">{phrase var='user.select_an_image'}:</label>
				</div>
				<div class="table_right">				
					<div id="js_progress_uploader2"></div>
					<div class="extra_info">
						{phrase var='user.you_can_upload_a_jpg_gif_or_png_file'}
						{if $iMaxFileSize !== null}
						<br />
						{phrase var='user.the_file_size_limit_is_file_size_if_your_upload_does_not_work_try_uploading_a_smaller_picture' file_size=$iMaxFileSize|filesize}
						{/if}
					</div>				
				</div>
				<div class="clear"></div>					
			</div>
			<div class="table_clear">
				<input type="submit" value="{phrase var='user.upload_picture'}" class="button" name="val[uploaded_master]" />
			</div>	
		</div>
		</div>
	</form>
</div>
{/if}
<form id='js_profile_edit_form' enctype="multipart/form-data" method="post" action="{url link='user.profile'}"{if !$bIsEdit} onsubmit="{plugin call='user.template_controller_profile_form_onsubmit'} $('#js_custom_public_message').hide(); $('#js_custom_submit_button').attr('disabled', true).addClass('disabled'); $('#js_custom_update_info').html($.ajaxProcess('{phrase var='user.updating_profile' phpfox_squote=true}')).show(); $(this).ajaxCall('custom.updateFields'); return false;"{/if}>
{if isset($iUserId)}
	<div><input type="hidden" name="id" value="{$iUserId}" /></div>
{/if}
<div class="table js_custom_groups js_custom_group_basic">
		{if Phpfox::isModule('pet')}
		<div class="separate"></div>
		<div class="table">
			<div class="table_left">			
				{required} {phrase var='user.full_name'}:
			</div>
			<div class="table_right">				
				<input type="text" name="val[full_name]" id="full_name" value="{value type='input' id='full_name'}" size="30" />			
			</div>
		</div>				
		{/if}
		<div class="table">
			<div class="table_left">
				<label for="country_iso">{required}{phrase var='user.location'}:</label>
			</div>
			<div class="table_right">
				{select_location}
				{module name='core.country-child'}
			</div>
			<div class="clear"></div>
		</div>

		<div class="table">
			<div class="table_left">
				<label for="city_location">{phrase var='user.city'}:</label>
			</div>
			<div class="table_right">
				<input type="text" name="val[city_location]" id="city_location" value="{value type='input' id='city_location'}" size="30" />
			</div>
			<div class="clear"></div>
		</div>

		<div class="table">
			<div class="table_left">
				<label for="postal_code">{phrase var='user.zip_postal_code'}:</label>
			</div>
			<div class="table_right">
				<input type="text" name="val[postal_code]" id="postal_code" value="{value type='input' id='postal_code'}" size="10" />
			</div>
			<div class="clear"></div>
		</div>

		<div class="separate"></div>
		{if Phpfox::getUserParam('user.can_edit_dob')}
		<div class="table">
			<div class="table_left">
				{required}{phrase var='user.date_of_birth'}:
			</div>
			<div class="table_right">
				{select_date start_year=$sDobStart end_year=$sDobEnd field_separator=' / ' field_order='MDY' bUseDatepicker=false sort_years='DESC'}
			</div>
			<div class="clear"></div>
		</div>
		{/if}
		{if Phpfox::getUserParam('user.can_edit_gender_setting')}
		<div class="table">
			<div class="table_left">
				<label for="gender">{required}{phrase var='user.gender'}:</label>
			</div>
			<div class="table_right">
				{select_gender}
			</div>
			<div class="clear"></div>
		</div>
		{/if}
		
		{if Phpfox::getParam('user.enable_relationship_status') && Phpfox::getUserParam('custom.can_have_relationship') && isset($aRelations) && !empty($aRelations)}
		<div class="table">
			<div class="table_left">
				{phrase var='custom.relationship_status'}
			</div>
			<div class="table_right">
				<select name="val[relation]" id="relation" onchange="$Behavior.displayRelationshipChange()">
					{foreach from=$aRelations item=aRelation}
						<option value="{$aRelation.relation_id}" {if isset($aForms.relation_id) && $aForms.relation_id == $aRelation.relation_id} selected="selected"{/if}>{phrase var=$aRelation.phrase_var_name} </option>
					{/foreach}
				</select>
				
				<script type="text/javascript">
					var aRelationshipChange = {$sJsArray};
					
					{if isset($aForms.relation_id)}
					$('#relation').val({$aForms.relation_id});
					{/if}
				</script>
				
				<span id="relation_with">
					<span class="js_relation_with_message" id="relation_with_message_to" style="display:none;">{phrase var='user.to'}:</span>
					<span class="js_relation_with_message" id="relation_with_message_with" style="display:none;">{phrase var='user.with'}:</span>
						<div class="edit_friend_relation">
										<span id="js_custom_search_friend"></span>	
										<span id="sFriendImage">
											{if isset($aForms.with_user) && isset($aForms.with_user.user_image) &&  !empty($aForms.with_user) && $aForms.with_user.with_user_id > 0}
												{img user=$aForms.with_user suffix='_50_square' max_height=50 max_height=50}
											{/if}
										</span>
										{if isset($aForms.with_user.user_id) && !empty($aForms.with_user.user_id)}
											<input type="hidden" id="relation_with_input_hidden" name="val[relation_with]" value="{$aForms.with_user.user_id}">
										{/if}
										<div id="js_custom_search_friend_placement"></div>
										
										<input type="hidden" name="val[previous_relation_with]" value="{if isset($aForms.with_user.user_id)}{$aForms.with_user.user_id}{else}0{/if}">
										<input type="hidden" name="val[previous_relation_type]" value="{if isset($aForms.relation_id)}{$aForms.relation_id}{else}0{/if}">
										{if isset($aForms.with_user.status_id) && $aForms.with_user.status_id == 1}
										<div style="margin-left:60px;">{phrase var='user.pending_confirmation'}</div>
										{/if}
						</div>
						{literal}
						<script type="text/javascript">
							$Core.searchFriends({
								'id': '#js_custom_search_friend',
								'placement': '#js_custom_search_friend_placement',
								'width': '300px',
								'max_search': 10,
								'input_name': 'friends',
								'default_value': {/literal}{if isset($aForms.with_user) && $aForms.with_user.with_user_id > 0}'{$aForms.with_user.full_name}' {else} '{phrase var='user.search_friends_by_their_name'}'{/if}{literal},
								'search_input_id' : 'sFriendInput',
								'onclick': function()
								{																	
									return false;
								},
								'onBeforePrepend' : function()
								{
									$('#sFriendInput').val($Core.searchFriendsInput.aFoundUser['full_name']);
									$Core.searchFriendsInput.sHtml = '';
									if ($('#sFriendImage').length < 1)
									{
										$('#sFriendInput').before('<span id="sFriendImage"></span>');
									}
									$('#sFriendImage').html('<span style=""><img src="'+$Core.searchFriendsInput.aFoundUser['user_image'] + '"></span>');
									$('#js_custom_search_friend_placement').hide();
									
									/* Make sure there's only one input with the name 
									 * -safe check for when user doesnt reload the page like in ajax browsing- */
									if ($('#relation_with_input_hidden').length > 0)
									{
										$('#relation_with_input_hidden').remove();
									}
									if ($('#relation_with_input_hidden').length < 1)
									{
										$('#sFriendImage').after('<input type="hidden" id="relation_with_input_hidden" name="val[relation_with]" value="' + $Core.searchFriendsInput.aFoundUser['user_id'] + '">');
									}
									else
									{
										$('#relation_with_input_hidden').val($Core.searchFriendsInput.aFoundUser['user_id']);
									}
								}
							});	
						</script>
						{/literal}
					
					
					
				</span>
			</div>
		</div>
		{/if}
		
		
		{if Phpfox::isModule('forum')}
		<div class="separate"></div>		
		<div class="table">
			<div class="table_left">
				{phrase var='user.forum_signature'}:
			</div>
			<div class="table_right">
				<textarea cols="40" rows="5" name="val[signature]">{$aForms.signature}</textarea>
			</div>
			<div class="clear"></div>
		</div>		
		{/if}
</div>

	{foreach from=$aSettings item=aSetting}
	{if $aSetting.field_name != 'pet_name'}	
	<div class="table js_custom_groups js_custom_group_{$aSetting.group_id}" style="display:none;">	
		<div class="table_left">
		{if $aSetting.is_required}{required}{/if}{phrase var=$aSetting.phrase_var_name}:
		</div>
		<div class="table_right">
			{if $aSetting.field_name == 'master_birthday' && $aSetting.product_id=='phpfox_ycus'}	
			<input id="roommates_master_birthday" type="text" name="custom[{$aSetting.field_id}]" value="{if isset($aSetting.value)}{$aSetting.value|clean}{/if}" size="30" maxlength="255"{if PHPFOX_IS_AJAX} style="width:90%;"{/if} />
			{else}
				{template file='custom.block.form'}
			{/if}
		</div>
	</div>
	{/if}	
	{/foreach}
	{plugin call='user.template_controller_profile_form'}
	<div class="table_clear">
		<input type="submit" value="{phrase var='user.update'}" class="button" id="js_custom_submit_button"> <span id="js_custom_update_info"></span>
	</div>
</form>

{else}
<div class="extra_info">
	{phrase var='user.no_custom_fields_have_been_added'}
	{if Phpfox::getUserParam('custom.can_add_custom_fields')}
	<ul class="action">
		<li><a href="{url link='admincp.custom.add'}">{phrase var='user.add_a_new_custom_field'}</a></li>
	</ul>
	{/if}
</div>
{/if}